<template>
    <label class="l-checkbox">
        <span class="l-checkbox__input">
            <span class="l-checkbox__inner"></span>
            <input type="checkbox" class="l-checkbox__original">
        </span>
        <span class="l-checkbox__label">
            <slot></slot>
            <template v-if="!$slots.default">{{label}}</template>
        </span>
    </label>
</template>

<script>
export default {
  name: 'LCheckbox',
  props: {
    label: {
      type: [String, Number, Boolean],
      default: ''
    }
  }
}
</script>

<style lang="scss">
.l-checkbox {
    color: #606266;
    font-weight: 500;
    font-size: 14px;
    position: relative;
    cursor: pointer;
    display: inline-block;
    white-space: nowrap;
    user-select: none;  // CSS3新属性，文本不能被选择
    margin-right: 30px;

    .l-checkbox__input {
        white-space: nowrap;
        cursor: pointer;
        outline: none;
        display: inline-block;
        line-height: 1;
        position: relative;
        vertical-align: middle;

        .l-checkbox__inner {
            display: inline-block;
            position: relative;
            width: 14px;
            height: 14px;
            border: 1px solid #dcdfe6;
            border-radius: 2px;
            box-sizing: border-box;
            background-color: #fff;
            z-index: 1;
            transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46), background-color 0.25s 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);

            // 在框中设置✔的样式
            &::after {
                box-sizing: content-box;
                content: '';
                height: 7px;
                width: 3px;
                border: 1px solid black;
                position: absolute;
                left: 4px;
                top: 1px;
                border-top: 0;
                border-left: 0;
                transform: rotate(45deg); // 顺时针旋转45°
                transition: transform 0.15s ease-in 0.05s;
                transform-origin: center;
            }
        }

        // 隐藏原来的复选框
        .l-checkbox__original {
            opacity: 0;
            outline: none;
            position: absolute;
            margin: 0;
            width: 0;
            height: 0;
            z-index: -1;
        }
    }

    .l-checkbox__label {
        display: inline-block;
        padding-left: 10px;
        line-height: 19px;
        font-size: 14px;
    }
}
</style>
